#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int maxn = 1e5+10;
int a[maxn];
int main()
{
	int t;
	scanf("%d",&t);
	while(t--)
	{
		int n,m;
		int low = 0;
		int high = 0;
		scanf("%d %d",&n,&m);
		for(int i = 0;i<n;i++)
		{
			scanf("%d",&a[i]);
			low = max(low,a[i]);
			high += a[i];
		}
		while(low<=high)
		{
			//printf("*********\n");
			int sum = 0;
			int mid = (low+high)>>1;
			int cnt  = 1;
			for(int i = 0;i<n;i++)
			{
				if(sum+a[i]<=mid)
				{
					sum += a[i];
				}
				else 
				{
					cnt++;
					sum = a[i];
				}
			}
			if(cnt>m) low = mid+1;
			else high = mid-1;
			//printf("***********%d %d %d\n",cnt,low,mid);
		}
		printf("%d\n",low);
	}
} 
